using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VDEVTERM
    {
        public DataRow Convert2DEVTERM(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryDEVTERM(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["DEVMANDANT"] = " ".PadRight(2 ); 
         dwReturn["DEVNR"] = " ".PadRight(0 ); 
         dwReturn["DEVSTATUS"] = " ".PadRight(1 ); 
         dwReturn["DEVKONTO"] = " ".PadRight(6 ); 
         dwReturn["DEVGESCHART"] = " ".PadRight(1 ); 
         dwReturn["DEVFAELLIG"] = " ".PadRight(0 ); 
         dwReturn["DEVABSCHLUS"] = " ".PadRight(0 ); 
         dwReturn["DEVANPARTN"] = " ".PadRight(40 ); 
         dwReturn["DEVWAEBETR"] = " ".PadRight(0 ); 
         dwReturn["DEVWAEHRSL"] = " ".PadRight(3 ); 
         dwReturn["DEVABGEBUCH"] = " ".PadRight(0 ); 
         dwReturn["DEVSTDKURS"] = " ".PadRight(0 ); 
         dwReturn["DEVTERKURSH"] = " ".PadRight(3 ); 
         dwReturn["DEVTERKURSM"] = " ".PadRight(4 ); 
         dwReturn["DEVTERKURS"] = " ".PadRight(0 ); 
         dwReturn["DEVKASKURS"] = " ".PadRight(0 ); 
         dwReturn["DEVKASKURSM"] = " ".PadRight(4 ); 
         dwReturn["DEVANMERK1"] = " ".PadRight(40 ); 
         dwReturn["DEVANMERK2"] = " ".PadRight(40 ); 
         dwReturn["DEVFILLER"] = " ".PadRight(98 ); 
         dwReturn["DEVAENZL"] = " ".PadRight(0 ); 
         dwReturn["DEVAENB"] = " ".PadRight(8 ); 
         dwReturn["DEVAEND"] = " ".PadRight(0 ); 
         dwReturn["DEVNEUB"] = " ".PadRight(8 ); 
         dwReturn["DEVNEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapDEVTERM(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveDEVTERM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryDEVTERM(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapDEVTERM(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertDEVTERM(dwLocal, ITXDBVERSION);
            }
            UpdateDEVTERM(dwLocal);
        }
        public void InsertDEVTERM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO DEVTERM(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryDEVTERM(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM DEVTERM WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM DEVTERM  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "DEVTERM";
            Return = Result;
            return Return;
        }
        public void DeleteDEVTERM(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM DEVTERM   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateDEVTERM(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE DEVTERM SET "
                    +"DEVMANDANT= :DEVMANDANT,"
                    +"DEVNR= :DEVNR,"
                    +"DEVSTATUS= :DEVSTATUS,"
                    +"DEVKONTO= :DEVKONTO,"
                    +"DEVGESCHART= :DEVGESCHART,"
                    +"DEVFAELLIG= :DEVFAELLIG,"
                    +"DEVABSCHLUS= :DEVABSCHLUS,"
                    +"DEVANPARTN= :DEVANPARTN,"
                    +"DEVWAEBETR= :DEVWAEBETR,"
                    +"DEVWAEHRSL= :DEVWAEHRSL,"
                    +"DEVABGEBUCH= :DEVABGEBUCH,"
                    +"DEVSTDKURS= :DEVSTDKURS,"
                    +"DEVTERKURSH= :DEVTERKURSH,"
                    +"DEVTERKURSM= :DEVTERKURSM,"
                    +"DEVTERKURS= :DEVTERKURS,"
                    +"DEVKASKURS= :DEVKASKURS,"
                    +"DEVKASKURSM= :DEVKASKURSM,"
                    +"DEVANMERK1= :DEVANMERK1,"
                    +"DEVANMERK2= :DEVANMERK2,"
                    +"DEVFILLER= :DEVFILLER,"
                    +"DEVAENZL= :DEVAENZL,"
                    +"DEVAENB= :DEVAENB,"
                    +"DEVAEND= :DEVAEND,"
                    +"DEVNEUB= :DEVNEUB,"
                    +"DEVNEUD= :DEVNEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("DEVMANDANT", OracleType.NVarChar).Value = dwData["DEVMANDANT"].ToString(); 
          or1.Parameters.Add("DEVNR", OracleType.NVarChar).Value = dwData["DEVNR"].ToString(); 
          or1.Parameters.Add("DEVSTATUS", OracleType.NVarChar).Value = dwData["DEVSTATUS"].ToString(); 
          or1.Parameters.Add("DEVKONTO", OracleType.NVarChar).Value = dwData["DEVKONTO"].ToString(); 
          or1.Parameters.Add("DEVGESCHART", OracleType.NVarChar).Value = dwData["DEVGESCHART"].ToString(); 
          or1.Parameters.Add("DEVFAELLIG", OracleType.NVarChar).Value = dwData["DEVFAELLIG"].ToString(); 
          or1.Parameters.Add("DEVABSCHLUS", OracleType.NVarChar).Value = dwData["DEVABSCHLUS"].ToString(); 
          or1.Parameters.Add("DEVANPARTN", OracleType.NVarChar).Value = dwData["DEVANPARTN"].ToString(); 
          or1.Parameters.Add("DEVWAEBETR", OracleType.NVarChar).Value = dwData["DEVWAEBETR"].ToString(); 
          or1.Parameters.Add("DEVWAEHRSL", OracleType.NVarChar).Value = dwData["DEVWAEHRSL"].ToString(); 
          or1.Parameters.Add("DEVABGEBUCH", OracleType.NVarChar).Value = dwData["DEVABGEBUCH"].ToString(); 
          or1.Parameters.Add("DEVSTDKURS", OracleType.NVarChar).Value = dwData["DEVSTDKURS"].ToString(); 
          or1.Parameters.Add("DEVTERKURSH", OracleType.NVarChar).Value = dwData["DEVTERKURSH"].ToString(); 
          or1.Parameters.Add("DEVTERKURSM", OracleType.NVarChar).Value = dwData["DEVTERKURSM"].ToString(); 
          or1.Parameters.Add("DEVTERKURS", OracleType.NVarChar).Value = dwData["DEVTERKURS"].ToString(); 
          or1.Parameters.Add("DEVKASKURS", OracleType.NVarChar).Value = dwData["DEVKASKURS"].ToString(); 
          or1.Parameters.Add("DEVKASKURSM", OracleType.NVarChar).Value = dwData["DEVKASKURSM"].ToString(); 
          or1.Parameters.Add("DEVANMERK1", OracleType.NVarChar).Value = dwData["DEVANMERK1"].ToString(); 
          or1.Parameters.Add("DEVANMERK2", OracleType.NVarChar).Value = dwData["DEVANMERK2"].ToString(); 
          or1.Parameters.Add("DEVFILLER", OracleType.NVarChar).Value = dwData["DEVFILLER"].ToString(); 
          or1.Parameters.Add("DEVAENZL", OracleType.NVarChar).Value = dwData["DEVAENZL"].ToString(); 
          or1.Parameters.Add("DEVAENB", OracleType.NVarChar).Value = dwData["DEVAENB"].ToString(); 
          or1.Parameters.Add("DEVAEND", OracleType.NVarChar).Value = dwData["DEVAEND"].ToString(); 
          or1.Parameters.Add("DEVNEUB", OracleType.NVarChar).Value = dwData["DEVNEUB"].ToString(); 
          or1.Parameters.Add("DEVNEUD", OracleType.NVarChar).Value = dwData["DEVNEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
